package com.example.shop_2305.adapter

import android.widget.RatingBar
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.Comment
import com.example.shop_2305.R
import com.example.shop_2305.utils.GlideUtils

class CommentAdapter:BaseQuickAdapter<Comment,BaseViewHolder>(R.layout.item_comment) {
    override fun convert(holder: BaseViewHolder, item: Comment) {
        GlideUtils.loadCircle(context,item.avatar,holder.getView(R.id.comment_image))
        holder.setText(R.id.comment_name,item.nickname)
        holder.setText(R.id.comment_time,item.createTime)
        holder.getView<RatingBar>(R.id.comment_rb).rating = item.score.toFloat()
        holder.setText(R.id.comment_content,item.comment)
        //评论图片//当有图的时候显示
        if(item.pics.size>0&&item.pics[0]!=""){
            //找到rv
            val rv = holder.getView<RecyclerView>(R.id.comment_rv_img)
            val imgAdapter = ImgAdapter()
            imgAdapter.data.addAll(item.pics)
            rv.adapter = imgAdapter
            rv.layoutManager = GridLayoutManager(context,3)
        }
    }
}

class ImgAdapter :BaseQuickAdapter<String,BaseViewHolder>(R.layout.item_comment_ing){
    override fun convert(holder: BaseViewHolder, item: String) {
        GlideUtils.loadNormal(context,item,holder.getView(R.id.img_iv))
    }

}